<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itheima" uri="http://itheima.com/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="$<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
<title>首页</title>
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<div class="navbar-brand" >论文管理系统</div> 
	</div>
	<!-- 导航栏右侧图标部分 -->
	<ul class="nav navbar-top-links navbar-right">
		<!-- 用户信息和退出 start -->
		<li class="dropdown">
			
			<ul >
				<li><a href="#"><i class="fa fa-user fa-fw"></i>
				               用户：${user.name}
				    </a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/loginout">
					<i class="fa fa-sign-out fa-fw"></i>退出登录
					</a>
				</li>
			</ul> 
		</li>
		<!-- 用户信息和系统设置结束 -->
	</ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" >
				<li>
				    <a href="${pageContext.request.contextPath }/student" class="active">
				      <i class="fa fa-edit fa-fw"></i> 学生管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/paper" class="active">
				      <i class="fa fa-dashboard fa-fw" ></i> 论文管理
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
    <!-- 客户列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">学生信息管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get" 
				      action="${pageContext.request.contextPath }/studentfindall">
					<div class="form-group">
						<label for="name">学生姓名</label> 
						<input type="text" class="form-control" id="name" 
						                   value="${name}" name="name" />
					</div>
					
					<div class="form-group">
						<label for="name">年级</label> 
						<input type="text" class="form-control" id="grade" 
						                   value="${grade}" name="grade" />
					</div>
				<div class="form-group">
						<label for="major">专业</label> 
						<input type="text" class="form-control" id="major" 
						                   value="${major}" name="major" />
					</div>
					<button type="submit" class="btn btn-primary">查询</button>
					<button type="button" class="btn btn-primary"  onclick="window.location.href='studentf'">显示所有学生信息</button>
				</form>
			</div>
		</div>
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newstudentDialog" onclick="clearstudent()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">学生信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>学生编号</th>
								<th>学生姓名</th>
								<th>年级</th>
								<th>专业</th>
								<th>联系方式</th>
								<th>论文数量</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.ID}</td>
									<td>${row.name}</td>
									<td>${row.grade}</td>
									<td>${row.major}</td>
									<td>${row.contact}</td>
									<td>${row.papernum}</td>
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#studentEditDialog" onclick= "editstudent(${row.ID})">修改</a>
										<a href="${pageContext.request.contextPath }/studentf" class="btn btn-danger btn-xs" onclick="deletestudent(${row.ID})">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<itheima:page url="${pageContext.request.contextPath }/studentfindall" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 客户列表查询部分  end-->
	
	
	
	
	<!-- 创建客户模态框 -->
<div class="modal fade" id="newstudentDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">添加学生信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_student_form">
					<div class="form-group">
						<label for="new_name" class="col-sm-2 control-label">
						    学生姓名
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_name" placeholder="学生姓名" name="name" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_grade" class="col-sm-2 control-label">
						    年级
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_grade" placeholder="年级" name="grade" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_major" class="col-sm-2 control-label">
						    专业
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_major" placeholder="专业" name="major" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_contact" class="col-sm-2 control-label">
						    联系方式
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_contact" placeholder="联系方式" name="contact" />
						</div>
					</div>
					
										<div class="form-group">
						<label for="new_papernum" class="col-sm-2 control-label">
						    论文数量
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_papernum" placeholder="论文数量" name="papernum" />
						</div>
					</div>								
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createstudent()">创建客户</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改客户模态框 -->
<div class="modal fade" id="studentEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改学生信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_student_form">
					<input type="hidden" id="edit_ID" name="ID"/>
					<div class="form-group">
						<label for="edit_name" class="col-sm-2 control-label">学生姓名</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_name" placeholder="学生姓名" name="name" />
						</div>
					</div>
					
					<div class="form-group">
						<label for="edit_grade" class="col-sm-2 control-label">年级</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_grade" placeholder="年级" name="grade" />
						</div>
					</div>
					
					<div class="form-group">
						<label for="edit_major" class="col-sm-2 control-label">专业</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_major" placeholder="专业" name="major" />
						</div>
					</div>
					
					<div class="form-group">
						<label for="edit_contact" class="col-sm-2 control-label">联系方式</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_contact" placeholder="联系方式" name="contact" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_papernum" class="col-sm-2 control-label">论文数量</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_papernum" placeholder="论文数量" name="papernum" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updatestudent()">保存修改</button>
			</div>
		</div>
	</div>
</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="${pageContext.request.contextPath }/js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="${pageContext.request.contextPath }/js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="${pageContext.request.contextPath }/js/jquery.dataTables.min.js"></script>
<script src="${pageContext.request.contextPath }/js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="${pageContext.request.contextPath }/js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建客户窗口中的数据
	function clearstudent() {
	    $("#new_name").val("");
	    $("#new_grade").val("")
	    $("#new_major").val("")
	    $("#new_contact").val("")
	    $("#new_papernum").val("");
	}
	// 创建客户
	function createstudent() {
	$.post("${pageContext.request.contextPath }/studentincrease",
	$("#new_student_form").serialize(),function(data){
	        if(data !=null){
	            alert("客户创建成功！");
	            window.location.reload();
	        }else{
	            alert("客户创建失败！");
	            window.location.reload();
	        }
	    });
	}
	// 通过id获取修改的客户信息
	function editstudent(ID) {
	    $.ajax({
	        type:"GET",
	        url:"<%=basePath%>studentfind",
	        data:{"ID":ID},
	        success:function(data) {
	            $("#edit_ID").val(data.ID);
	            $("#edit_name").val(data.name);
	            $("#edit_major").val(data.major);
	            $("#edit_grade").val(data.grade);
	            $("#edit_contact").val(data.contact);
	            $("#edit_papernum").val(data.papernum)
	        }
	    });
	    alert(data.name);
	}
    // 执行修改客户操作
	function updatestudent() {
		$.post("${pageContext.request.contextPath }/studentupdate",$("#edit_student_form").serialize(),function(data){
			if(data!=null){
				alert("客户信息更新成功！");
				window.location.reload();
			}else{
				alert("客户信息更新失败！");
				window.location.reload();
			}
		});
	}
	// 删除客户
	function deletestudent(ID) {
	    if(confirm('确实要删除该客户吗?')) {
			$.post("${pageContext.request.contextPath }/studentdelete",{"ID":ID});
			alert("客户删除成功！");
	    }
	}
</script>
</body>
</html>